package 字节流写数据;


import java.io.FileOutputStream;
import java.io.IOException;


public class FileOutputStreamDemo04 {
    public static void main(String[] args) {
//        try {
//        FileOutputStream fos =new FileOutputStream("fos.txt");
//        fos.write("hello".getBytes());
//        fos.close();
//        }catch (IOException e){
//            e.printStackTrace();
//        }
        //加入finally实现释放资源
        FileOutputStream fos = null;//初始化
        try {
            fos = new FileOutputStream("fos.txt");
            fos.write("hello".getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}